package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsGoodsProductMapper;
import com.qf.mapper.DtsOrderMapper;
import com.qf.pojo.DtsGoodsProduct;
import com.qf.pojo.DtsOrder;
import com.qf.service.DtsGoodsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author wanghaotian
 * time:2022/12/16,0016 10:12
 * description:
 */

@Service
public class DtsGoodsProductServiceImpl implements DtsGoodsProductService {

    @Autowired
    private DtsGoodsProductMapper productMapper;

    @Override
    public int count() {
        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getDeleted,false);
        return productMapper.selectCount(wrapper);
    }

    @Override
    public List<DtsGoodsProduct> findProductByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getGoodsId,id);
        wrapper.eq(DtsGoodsProduct::getDeleted,false);
        List<DtsGoodsProduct> products = productMapper.selectList(wrapper);
        return products;
    }

    @Override
    public void deleteByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getGoodsId,id);
        productMapper.delete(wrapper);
    }

    @Override
    public void insert(DtsGoodsProduct product) {
        product.setAddTime(new Date());
        product.setDeleted(false);
        product.setUpdateTime(new Date());
        productMapper.insert(product);
    }
}
